package main

import (
	"fmt"
	"gitee.com/masaichi/mastool/utils"
	"github.com/panjf2000/ants/v2"
	"golang.org/x/sync/errgroup"
	"log"
	"sync"
	"time"
)

func main() {
	fmt.Println(utils.GetExt("123.jpg"))
	pool()
}

// 协程池
func pool() {
	p, err := ants.NewPool(5)
	if err != nil {
		log.Fatal(err)
	}
	defer p.Release()
	wg := sync.WaitGroup{}
	wg.Add(1)
	p.Submit(func() {
		defer wg.Done()
		log.Printf("111")
	})
	wg.Wait()
	log.Printf("end")
}

// 并发处理
func bingfa() {
	w := errgroup.Group{}

	w.Go(func() error {
		log.Printf("one:111")
		return nil
	})
	w.Go(func() error {
		log.Printf("one:222")
		tt := time.NewTicker(10 * time.Second)
		for {
			<-tt.C
			break
		}
		log.Printf("one:222 finish")
		return nil
	})

	if err := w.Wait(); err != nil {
		log.Printf("err:%v", err)
	}
}
